<?php
	function f140($sql){
		//data handle instance
		//set request
		//define format
		//set format
		//define query string
		//process time
		//process fitler
		$dataHandle = new DataHandle();
		$dataHandle->setRequest("140");

		$format = array(
			"ModifiedDate" => "datem/d/Y",
			);

		$dataHandle->setFormat($format);

		$action = getValue($_GET['action']);

		if ($action == "getItems"){
			$query = getJSONQuery();
			print($dataHandle->printJSON($sql, $query));
		}
		else if($action == "addItems"){
			var_dump($dataHandle->addItemsQuery($sql,$_GET,"mix_Products"));
		}
		else if($action == "updateItems"){
			var_dump($dataHandle->updateItemsQuery($sql,$_GET, "mix_Products"));
		}
		else if($action == "deleteItems"){
			var_dump($dataHandle->deleteItemsQuery($sql,$_GET, "mix_Products"));
		}	
		else{
			$temp = array();
			$temp['error'] = "140: Bad request";
			print(json_encode($temp));
		}

		unset($dataHandle);

	}

	function getJSONQuery(){
		$queryString = "
		SELECT
			mix_Products.product_id,
			mix_Products.description,
			mix_Product_Dest.description as destDescription,
			mix_Products.modified_by,
			mix_Products.modified_date
		FROM mix_Products
		inner join mix_Product_Dest on
		mix_Products.id_dest = mix_Product_Dest.id_dest";

		$oderByFiled = getValue($_GET['sortItem']);
		$oderByValue = getValue($_GET['ascDesc']);

		if($oderByFiled !== "" and $oderByValue !== "")
			$queryString = $queryString." order by ".$oderByFiled." ".$oderByValue;

		return $queryString;
	}
?>